package com.bicon.botu.mall.goods.api;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.bicon.botu.mall.goods.commons.GoodsConstants;
import com.bicon.botu.mall.goods.entity.Brand;
import com.bicon.botu.core.base.common.entity.BaseResult;
import com.bicon.botu.mall.goods.service.IBrandService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 前端品牌对接接口
 *
 * @Author: 吕祥
 * @Date: Created in 15:44 2017/8/25/025
 */
@RestController
@RequestMapping("/V1.0.0/api/brand")
public class BrandApi {

    @Autowired
    private IBrandService iBrandService;

    /**
     * 根据分类path查询品牌
     *
     * @param path 分类path
     * @return
     */
    @RequestMapping(value = "findByPath", method = RequestMethod.POST)
    public BaseResult findByPath(@RequestParam String path) {
        if (StringUtils.isBlank(path)) {
            return new BaseResult(GoodsConstants.RESPONSE_CODE_400, GoodsConstants.RESPONSE_MESSAGE_400);
        }
        return iBrandService.findByClassPath(path);
    }

    /**
     * 查询所有品牌
     *
     * @return
     */
    @RequestMapping(value = "findAll", method = RequestMethod.POST)
    public BaseResult findAll() {
        List<Brand> brandList = new Brand().selectList(new EntityWrapper().eq("state", GoodsConstants.BRAND_ENABLED).eq("logic_delete", GoodsConstants.DEL_LOGIC_NORMAL).orderBy("create_date", false));
        return new BaseResult(GoodsConstants.RESPONSE_CODE_200, GoodsConstants.RESPONSE_MESSAGE_200, brandList);
    }
}
